import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 客户,报备相关接口
 *
 * allen  2021-08-24
 */

/**
 * 查询我的客户列表
 */
const queryCustomerList = (words, zone, buyDegree, buyHouseCategory) => {
  return new Promise((resolve, reject) => {
    get("/user/customer/index?words=" + words + "&zone=" + zone + "&buyDegree=" + buyDegree + "&buyHouseCategory=" + buyHouseCategory).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 创建一条报备信息
 * @param {*} data 
 */
const createRecommendInfo = (data) => {
  return new Promise((resolve, reject) => {
    post("/recommend/create", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 获取报备记录列表
 * @param {*} page 
 * @param {*} pageSize 
 * @param {*} status 
 */
const queryRecommendList = (page, pageSize, status, words = "") => {
  return new Promise((resolve, reject) => {
    get("/recommend/index", {
      page: page,
      pageSize: pageSize,
      status: status,
      words: words
    }).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 查询报备详情
 * @param {*} id 
 */
const queryRecommendDetail = (id) => {
  return new Promise((resolve, reject) => {
    get("/recommend/detail", {
      id: id
    }).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 更新报备信息
 * @param {*} data 
 */
const updateRecommendDetail = (data) => {
  return new Promise((resolve, reject) => {
    put("/recommend/update/status", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 创建客户
 * @param {*} data 
 */
const createClientUser = (data) => {
  return new Promise((resolve, reject) => {
    post("/user/customer/create", data).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 更新客户信息
 * @param {*} data 
 */
const updateClientUser = (data) => {
  return new Promise((resolve, reject) => {
    post("/user/customer/update", data).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 根据id删除一个客源
 * @param {*} id 
 */
const deleteClientUser = (id) => {
  return new Promise((resolve, reject) => {
    get("/user/customer/delete", {
      id: id
    }).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 根据id查询客户详情
 * @param {*} id 
 */
const queryClientDetail = (id) => {
  return new Promise((resolve, reject) => {
    get("/user/customer/detail", {
      id: id
    }).
      then((data) => {
        if (data.code == 200) {
          resolve(data)
        } else {
          reject(data.msg)
        }
      }).
      catch((e) => {
        reject(e.message)
      })
  })
}

/**
 * 创建跟进信息
 */
const createFollowInfo = (data) => {
  return new Promise((resolve, reject) => {
    post("/user/customer/create/follow", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 获取个人中心自己的报备数量
 */
const recommendPersonalNumber = () => {
  return new Promise((resolve, reject) => {
    get("/recommend/personal/number").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }

    }).catch((e) => {
      reject(e.message)
    })
  })
}



module.exports = {
  queryCustomerList,
  createRecommendInfo,
  queryRecommendList,
  queryRecommendDetail,
  updateRecommendDetail,
  createClientUser,
  updateClientUser,
  deleteClientUser,
  queryClientDetail,
  createFollowInfo,
  recommendPersonalNumber
}
